using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
	public class InfosController : BaseController 
	{
		private readonly IInfosServer _iInfosServer;

		public InfosController (IInfosServer iInfosServer)
		{
			_iInfosServer = iInfosServer;
		}
		
		/// <summary>
		/// 添加
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<IActionResult> Add(RequestCreateInfosDto dto)
		{
			return Send(await _iInfosServer.AddAsync(dto));
		}

		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<IActionResult> Update(RequestUpdateInfosDto dto)
		{
			return Send(await _iInfosServer.UpdateAsync(dto));
		}

		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<IActionResult> Delete(RequestDeleteInfosDto dto)
		{
			return Send(await _iInfosServer.DeleteAsync(dto));
		}

		/// <summary>
		/// 详情
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<IActionResult> Detail(int id)
		{
			return Send(await _iInfosServer.DetailAsync(id));
		}
		
		/// <summary>
		/// 分页
		/// </summary>
		/// <param name="page">当前是第几页</param>
		/// <param name="limit">一页有多少条数据</param>
		/// <param name="key">要查询的关键字</param>
		/// <returns></returns>
		[HttpGet]
		public async Task<IActionResult> Pagination(int page,int limit,string? key)
		{
			return Send(await _iInfosServer.PaginationAsync(page,limit,key));
		}
	}
}
	